#pragma once

#include "../util/external/ExternalHead.h"
#include "cocos2d.h"

class SocketMgr
{
public:
	
	static SocketMgr* inst()
	{
		static SocketMgr* instance = new SocketMgr();
		return instance;
	}

	~SocketMgr(void);

	bool initSocket(std::string ip, short adport);

	template<typename t_class, typename t_fun>
	bool addEventListener( int cmd, t_class *obj, t_fun objFun )
	{
		char buff[8]={0};
		snprintf(buff, 8, "%d", cmd);
		return _eventContainer.addEventListener(buff, obj, objFun);
	}

	template<typename t_class, typename t_fun>
	bool removeEventListener( int cmd, t_class *obj, t_fun objFun)
	{
		char buff[8]={0};
		snprintf(buff, 8, "%d", cmd);
		return _eventContainer.removeEventListener(buff, obj, objFun);
	}


	void sendMsg(TagNetMsg* data);
	void recvMsg(void* data);
private:

	SocketMgr(void);

private:
	ClientSocket						_clientSocket;
	EventContainer					_eventContainer;
};

